import router from './router'
import store from './store'
import { getToken } from '@/utils/auth' // get token from cookie

// const whiteList = ['/login'] // no redirect whitelist

router.beforeEach(async(to, from, next) => {

  // determine whether the user has logged in
  const hasToken = getToken()
  if (hasToken) {
      const hasGetUserInfo = store.state.loginName;
      if (hasGetUserInfo) { 
        next()
      } else {
          //获取用户信息
          await store.dispatch('getUserInfo')
          next()
      }
  } else {
    /*没有token*/
      // 重定向到登录页面。 
      // console.log(to.path)
      if(to.path == '/userCenter/userInfo'){
        next('/')
      }else{
        next()
      }
      
    
  }
})


